package com.huaxiafinance.management.service.impl;


import com.huaxiafinance.management.dto.request.InviteDto;
import com.huaxiafinance.management.mapper.UserInviteDetailsMapper;
import com.huaxiafinance.management.model.UserInviteDetails;
import com.huaxiafinance.management.service.UserInviteService;
import com.huaxiafinance.management.util.DateUtil;
import com.huaxiafinance.management.util.MessageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
@SuppressWarnings("SpringJavaAutowiringInspection")
@Transactional
public class UserInviteServiceImpl implements UserInviteService {

    @Autowired
    private UserInviteDetailsMapper userInviteDetailsMapper;


    /**
     * 請求用戶邀請的列表
     * @param dto
     * @return
     * @throws Exception
     */
    @Override
    public MessageResult queryInviteDetails(InviteDto dto) throws Exception {
        MessageResult messageResult = new MessageResult();
        if (dto.getStartTime()!=null&&dto.getEndTime()!=null){
            Map<String,Date> dateFormat = DateUtil.getTimeFormat(dto.getStartTime(),dto.getEndTime());
            dto.setStartDate(dateFormat.get("beginTime"));
            dto.setEndDate(dateFormat.get("overTime"));
            dto.setPage(dto.getPage() * dto.getRows());
            //查詢列表
            List<UserInviteDetails> userInviteDetailsList = userInviteDetailsMapper.queryUserInvites(dto);
            //統計數量
            int countInvites = userInviteDetailsMapper.countUserInvites(dto);
            messageResult.setData(userInviteDetailsList);
            messageResult.setRows(countInvites);
        }
        messageResult.setSuccessResult();
        return messageResult;
    }

}
